// Ignore argument count for test functions.
#![allow(clippy::too_many_arguments)]

use ndarray::{array, Array2};
use rstest::rstest;

use crate::tests::fixtures::{
    neighbor_association_tile_list,
    rand_bool,
    rand_usize,
    random_direction,
    random_last_leaves,
    random_missing_tile_policy,
    random_predecessor,
    random_tile_selection_policy,
    RANDOM_BOOL,
    RANDOM_COORDINATES,
    RANDOM_USIZE,
    RANDOM_VACANCY_POLICY,
};
use crate::tiling::slot_grid::tests::{
    create_grid_slot_or_none,
    create_grid_slot_with_tile_id,
    pad_coordinates_randomly,
    pad_grid_randomly,
};
use crate::tiling::tiles::{ArrayInitializable, TileConnectionArray};
use crate::tiling::{Direction, GridSlot, SlotGrid};

// There are identical arrays used in the following cases. Hard-coding and
// repetition is fine in test data, so
// noinspection DuplicatedCode
#[rstest]
// region wanted slot reached, small
#[case::wanted_slot_reached_small(
    pad_coordinates_randomly((1, 1)),
    random_direction(),
    pad_coordinates_randomly((1, 1)),
    random_direction(),
    rand_bool(),
    Some(pad_coordinates_randomly((1, 1))),
    // ╭───╮
    // │ ? │
    // ╰───╯
    pad_grid_randomly(array![
        [None, None],
        [None, create_grid_slot_or_none()],
    ]),
    ((0, 0), Direction::North, false, true),
)]
// endregion
// region wanted slot reached, large
#[case::wanted_slot_reached_large(
    pad_coordinates_randomly((rand_usize(1, 6), rand_usize(1, 6))),
    random_direction(),
    pad_coordinates_randomly(RANDOM_COORDINATES[0]),
    random_direction(),
    rand_bool(),
    Some(pad_coordinates_randomly(RANDOM_COORDINATES[0])),
    // ╭───────────╮
    // │ ? ? ? ? ? │
    // │ ? ? ? ? ? │
    // │ ? ? ? ? ? │
    // │ ? ? ? ? ? │
    // │ ? ? ? ? ? │
    // ╰───────────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            None,
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
    ]),
    ((0, 0), Direction::North, false, true),
)]
// endregion
// region curr. dir N, no wanted slot, curr. slot W, cursor center, curr. slot reached
#[case::curr_dir_n_no_wanted_slot_curr_slot_w_cursor_center_curr_slot_reached(
    pad_coordinates_randomly((2, 1)),
    Direction::East,
    pad_coordinates_randomly((2, 2)),
    Direction::North,
    *RANDOM_BOOL,
    None,
    // ╭───────╮
    // │ ? ² ? │
    // │ C   ³ │
    // │ ? ? ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(0, 3))),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(0, 4))),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((2, 1)), Direction::West, *RANDOM_BOOL, false),
)]
// endregion
// region curr. dir N, no wanted slot, curr. slot W, cursor center, curr. slot reached, exposed E
#[case::curr_dir_n_no_wanted_slot_curr_slot_w_cursor_center_curr_slot_reached_exposed_e(
    pad_coordinates_randomly((2, 1)),
    Direction::East,
    pad_coordinates_randomly((2, 2)),
    Direction::North,
    *RANDOM_BOOL,
    None,
    // ╭───────╮
    // │ ? ² ? │
    // │ C   ⁸ │
    // │ ? ? ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(0, 3))),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(4, 9))),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((2, 1)), Direction::West, true, false),
)]
// endregion
// region curr. dir N, no wanted slot, curr. slot W, cursor center, curr. slot reached, exposed N
#[case::curr_dir_n_no_wanted_slot_curr_slot_w_cursor_center_curr_slot_reached_exposed_n(
    pad_coordinates_randomly((2, 1)),
    Direction::East,
    pad_coordinates_randomly((2, 2)),
    Direction::North,
    *RANDOM_BOOL,
    None,
    // ╭───────╮
    // │ ? ⁷ ? │
    // │ C   ³ │
    // │ ? ? ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(5, 8))),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(0, 4))),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((2, 1)), Direction::West, true, false),
)]
// endregion
// region curr. dir N, no wanted slot, curr. slot E, cursor N border, curr. slot reached
#[case::curr_dir_n_no_wanted_slot_curr_slot_e_cursor_n_border_curr_slot_reached(
    pad_coordinates_randomly((1, 3)),
    Direction::West,
    pad_coordinates_randomly((1, 2)),
    Direction::North,
    *RANDOM_BOOL,
    None,
    // ╭───────╮
    // │ ?   C │
    // │ ? ? ? │
    // │ ? ? ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            None,
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((1, 3)), Direction::East, *RANDOM_BOOL, false),
)]
// endregion
// region curr. dir N, wanted slot E past border, curr. slot N, cursor E border, curr. slot reached
#[case::curr_dir_n_wanted_slot_e_past_border_curr_slot_n_cursor_e_border_curr_slot_reached(
    (1 + *RANDOM_USIZE, 3 + *RANDOM_USIZE * 4),
    Direction::South,
    (2 + *RANDOM_USIZE, 3 + *RANDOM_USIZE * 4),
    Direction::North,
    *RANDOM_BOOL,
    Some((2 + *RANDOM_USIZE, 4 + *RANDOM_USIZE * 4)),
    // ╭───────╮
    // │ ? ? C │
    // │ ? ?   │ W
    // │ ? ? ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            None,
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
    ]),
    (
        (1 + *RANDOM_USIZE, 3 + *RANDOM_USIZE * 4),
        Direction::North,
        *RANDOM_BOOL,
        false,
    ),
)]
// endregion
// region curr. dir N, wanted slot N, cursor center, no slot E, go E
#[case::curr_dir_n_wanted_slot_n_cursor_center_no_slot_e_go_e(
    pad_coordinates_randomly((3, rand_usize(1, 4))),
    Direction::North,
    pad_coordinates_randomly((2, 2)),
    Direction::North,
    *RANDOM_BOOL,
    Some(pad_coordinates_randomly((1, 2))),
    // ╭───────╮
    // │ ? W ? │
    // │ ?     │
    // │ ? ? ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            None,
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            None,
            None,
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((2, 3)), Direction::East, *RANDOM_BOOL, false),
)]
// endregion
// region curr. dir N, wanted slot N, cursor center, no tile E, go E
#[case::curr_dir_n_wanted_slot_n_cursor_center_no_tile_e_go_e(
    pad_coordinates_randomly((3, rand_usize(1, 4))),
    Direction::North,
    pad_coordinates_randomly((2, 2)),
    Direction::North,
    *RANDOM_BOOL,
    Some(pad_coordinates_randomly((1, 2))),
    // ╭───────╮
    // │ ? W ? │
    // │ ?     │
    // │ ? ? ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            None,
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            None,
            create_grid_slot_with_tile_id(None),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((2, 3)), Direction::East, *RANDOM_BOOL, false),
)]
// endregion
// region curr. dir N, wanted slot S, curr. slot N, cursor W border, curr. slot reached
#[case::curr_dir_n_wanted_slot_s_curr_slot_n_cursor_w_border_curr_slot_reached(
    pad_coordinates_randomly((1, 1)),
    Direction::South,
    pad_coordinates_randomly((2, 1)),
    Direction::North,
    true,
    Some(pad_coordinates_randomly((3, 1))),
    // ╭───────╮
    // │ C ? ? │
    // │   ³ ? │
    // │ W ? ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            None,
            None,
            None,
        ],
        [
            None,
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(0, 4))),
            create_grid_slot_or_none(),
        ],
        [
            None,
            None,
            None,
            None,
        ],
    ]),
    (pad_coordinates_randomly((1, 1)), Direction::North, true, false),
)]
// endregion
// region curr. dir N, wanted slot S, cursor center, no slot N, go N
#[case::curr_dir_n_wanted_slot_s_cursor_center_no_slot_n_go_n(
    pad_coordinates_randomly((3, rand_usize(1, 4))),
    Direction::North,
    pad_coordinates_randomly((2, 2)),
    Direction::North,
    *RANDOM_BOOL,
    Some(pad_coordinates_randomly((3, 2))),
    // ╭───────╮
    // │ ?   ? │
    // │ ?   ³ │
    // │ ? W ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            None,
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(0, 4))),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((1, 2)), Direction::North, *RANDOM_BOOL, false),
)]
// endregion
// region curr. dir N, wanted slot S, cursor center, no slot N, go N, exposed E
#[case::curr_dir_n_wanted_slot_s_cursor_center_no_slot_n_go_n_exposed_e(
    pad_coordinates_randomly((3, rand_usize(1, 4))),
    Direction::North,
    pad_coordinates_randomly((2, 2)),
    Direction::North,
    *RANDOM_BOOL,
    Some(pad_coordinates_randomly((3, 2))),
    // ╭───────╮
    // │ ?   ? │
    // │ ?   ⁸ │
    // │ ? W ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            None,
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(4, 9))),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((1, 2)), Direction::North, true, false),
)]
// endregion
// region curr. dir N, wanted slot S, cursor center, no slot W, go W
#[case::curr_dir_n_wanted_slot_s_cursor_center_no_slot_w_go_w(
    pad_coordinates_randomly((3, rand_usize(1, 4))),
    Direction::West,
    pad_coordinates_randomly((2, 2)),
    Direction::North,
    *RANDOM_BOOL,
    Some(pad_coordinates_randomly((3, 2))),
    // ╭───────╮
    // │ ? ² ? │
    // │     ³ │
    // │ ? W ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(0, 3))),
            create_grid_slot_or_none(),
        ],
        [
            None,
            None,
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(0, 4))),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((2, 1)), Direction::West, *RANDOM_BOOL, false),
)]
// endregion
// region curr. dir N, wanted slot S, cursor center, no slot W, go W, exposed N
#[case::curr_dir_n_wanted_slot_s_cursor_center_no_slot_w_go_w_exposed_n(
    pad_coordinates_randomly((3, rand_usize(1, 4))),
    Direction::West,
    pad_coordinates_randomly((2, 2)),
    Direction::North,
    *RANDOM_BOOL,
    Some(pad_coordinates_randomly((3, 2))),
    // ╭───────╮
    // │ ? ⁷ ? │
    // │     ³ │
    // │ ? W ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(5, 8))),
            create_grid_slot_or_none(),
        ],
        [
            None,
            None,
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(0, 4))),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((2, 1)), Direction::West, true, false),
)]
// endregion
// region curr. dir N, wanted slot S, cursor center, no tile W, go W
#[case::curr_dir_n_wanted_slot_s_cursor_center_no_tile_w_go_w(
    pad_coordinates_randomly((3, rand_usize(1, 4))),
    Direction::West,
    pad_coordinates_randomly((2, 2)),
    Direction::North,
    *RANDOM_BOOL,
    Some(pad_coordinates_randomly((3, 2))),
    // ╭───────╮
    // │ ? ² ? │
    // │     ³ │
    // │ ? ₂ ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(0, 3))),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_with_tile_id(None),
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(0, 4))),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(2, 5))),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((2, 1)), Direction::West, *RANDOM_BOOL, false),
)]
// endregion
// region curr. dir N, wanted slot S, cursor center, no tile W, go W, exposed N and E
#[case::curr_dir_n_wanted_slot_s_cursor_center_no_tile_w_go_w_exposed_n_and_e(
    pad_coordinates_randomly((3, rand_usize(1, 4))),
    Direction::West,
    pad_coordinates_randomly((2, 2)),
    Direction::North,
    *RANDOM_BOOL,
    Some(pad_coordinates_randomly((3, 2))),
    // ╭───────╮
    // │ ? ⁷ ? │
    // │     ⁸ │
    // │ ? ₂ ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(5, 8))),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_with_tile_id(None),
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(4, 9))),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(2, 5))),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((2, 1)), Direction::West, true, false),
)]
// endregion
// region curr. dir N, wanted slot SE, cursor center, nowhere to go, panic
#[should_panic(expected = "neither vacant nor wanted nor current slot found")]
#[case::curr_dir_n_wanted_slot_se_cursor_center_nowhere_to_go_panic(
    pad_coordinates_randomly((1 + rand_usize(0, 2) * 2, 1 + rand_usize(0, 2) * 2)),
    random_direction(),
    pad_coordinates_randomly((2, 2)),
    Direction::North,
    rand_bool(),
    Some(pad_coordinates_randomly((3, 3))),
    // ╭───────╮
    // │ ? ² ? │
    // │ ₃   ³ │
    // │ ? ₂ ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(0, 3))),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(3, 5))),
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(0, 4))),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(2, 5))),
            create_grid_slot_or_none(),
        ],
    ]),
    (
        (rand_usize(0, 9), rand_usize(0, 9)),
        random_direction(),
        rand_bool(),
        rand_bool(),
    ),
)]
// endregion
// region curr. dir N, wanted slot SE, cursor center, nowhere to go, exposed S, panic
#[should_panic(expected = "neither vacant nor wanted nor current slot found")]
#[case::curr_dir_n_wanted_slot_se_cursor_center_nowhere_to_go_exposed_s_panic(
    pad_coordinates_randomly((1 + rand_usize(0, 2) * 2, 1 + rand_usize(0, 2) * 2)),
    random_direction(),
    pad_coordinates_randomly((2, 2)),
    Direction::North,
    rand_bool(),
    Some(pad_coordinates_randomly((3, 3))),
    // ╭───────╮
    // │ ? ² ? │
    // │ ₃   ³ │
    // │ ? ₇ ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(0, 3))),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(3, 5))),
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(0, 4))),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(7, 10))),
            create_grid_slot_or_none(),
        ],
    ]),
    (
        (rand_usize(0, 9), rand_usize(0, 9)),
        random_direction(),
        rand_bool(),
        rand_bool(),
    ),
)]
// endregion
// region curr. dir N, maybe wanted slot SE, curr. slot blocked E, cursor center, no tile N, go N
#[case::curr_dir_n_maybe_wanted_slot_se_curr_slot_blocked_e_cursor_center_no_tile_n_go_n(
    pad_coordinates_randomly((2, 3)),
    if rand_bool() { Direction::North } else { Direction::East },
    pad_coordinates_randomly((2, 2)),
    Direction::North,
    *RANDOM_BOOL,
    if rand_bool() { Some(pad_coordinates_randomly((3, 3))) } else { None },
    // ╭───────╮
    // │ ?   ? │
    // │ ?     │
    // │ ? ? ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            None,
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            None,
            None,
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((1, 2)), Direction::North, *RANDOM_BOOL, false),
)]
// endregion
// region curr. dir E, no wanted slot, curr. slot N, cursor center, curr. slot reached
#[case::curr_dir_e_no_wanted_slot_curr_slot_n_cursor_center_curr_slot_reached(
    pad_coordinates_randomly((1, 2)),
    Direction::South,
    pad_coordinates_randomly((2, 2)),
    Direction::East,
    *RANDOM_BOOL,
    None,
    // ╭───────╮
    // │ ? C ? │
    // │ ?   ³ │
    // │ ? ₂ ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(0, 4))),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(2, 5))),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((1, 2)), Direction::North, *RANDOM_BOOL, false),
)]
// endregion
// region curr. dir E, no wanted slot, curr. slot N, cursor center, curr. slot reached, exposed S
#[case::curr_dir_e_no_wanted_slot_curr_slot_n_cursor_center_curr_slot_reached_exposed_s(
    pad_coordinates_randomly((1, 2)),
    Direction::South,
    pad_coordinates_randomly((2, 2)),
    Direction::East,
    *RANDOM_BOOL,
    None,
    // ╭───────╮
    // │ ? C ? │
    // │ ?   ³ │
    // │ ? ₇ ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(0, 4))),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(7, 10))),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((1, 2)), Direction::North, true, false),
)]
// endregion
// region curr. dir E, no wanted slot, curr. slot N, cursor center, curr. slot reached, exposed E
#[case::curr_dir_e_no_wanted_slot_curr_slot_n_cursor_center_curr_slot_reached_exposed_e(
    pad_coordinates_randomly((1, 2)),
    Direction::South,
    pad_coordinates_randomly((2, 2)),
    Direction::East,
    *RANDOM_BOOL,
    None,
    // ╭───────╮
    // │ ? C ? │
    // │ ?   ⁸ │
    // │ ? ₂ ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(4, 9))),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(2, 5))),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((1, 2)), Direction::North, true, false),
)]
// endregion
// region curr. dir E, no wanted slot, curr. slot S, cursor E border, curr. slot reached
#[case::curr_dir_e_no_wanted_slot_curr_slot_s_cursor_e_border_curr_slot_reached(
    pad_coordinates_randomly((3, 3)),
    Direction::North,
    pad_coordinates_randomly((2, 3)),
    Direction::East,
    *RANDOM_BOOL,
    None,
    // ╭───────╮
    // │ ? ? ? │
    // │ ? ?   │
    // │ ? ? C │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            None,
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((3, 3)), Direction::South, *RANDOM_BOOL, false),
)]
// endregion
// region curr. dir E, wanted slot S past border, curr. slot E, cursor S border, curr. slot reached
#[case::curr_dir_e_wanted_slot_s_past_border_curr_slot_e_cursor_s_border_curr_slot_reached(
    (3 + *RANDOM_USIZE * 3, 3 + *RANDOM_USIZE * 4),
    Direction::West,
    (3 + *RANDOM_USIZE * 3, 2 + *RANDOM_USIZE * 4),
    Direction::East,
    *RANDOM_BOOL,
    Some((4 + *RANDOM_USIZE * 3, 2 + *RANDOM_USIZE * 4)),
    // ╭───────╮
    // │ ? ? ? │
    // │ ? ? ? │
    // │ ?   C │
    // ╰───────╯
    //     W
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            None,
            create_grid_slot_or_none(),
        ],
    ]),
    (
        (3 + *RANDOM_USIZE * 3, 3 + *RANDOM_USIZE * 4),
        Direction::East,
        *RANDOM_BOOL,
        false,
    ),
)]
// endregion
// region curr. dir E, wanted slot E, cursor center, no slot S, go S
#[case::curr_dir_e_wanted_slot_e_cursor_center_no_slot_s_go_s(
    pad_coordinates_randomly((rand_usize(1, 4), 1)),
    Direction::South,
    pad_coordinates_randomly((2, 2)),
    Direction::East,
    *RANDOM_BOOL,
    Some(pad_coordinates_randomly((2, 3))),
    // ╭───────╮
    // │ ? ? ? │
    // │ ?   W │
    // │ ?   ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            None,
            None,
        ],
        [
            None,
            create_grid_slot_or_none(),
            None,
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((3, 2)), Direction::South, *RANDOM_BOOL, false),
)]
// endregion
// region curr. dir E, wanted slot E, cursor center, no tile S, go S
#[case::curr_dir_e_wanted_slot_e_cursor_center_no_tile_s_go_s(
    pad_coordinates_randomly((rand_usize(1, 4), 1)),
    Direction::South,
    pad_coordinates_randomly((2, 2)),
    Direction::East,
    *RANDOM_BOOL,
    Some(pad_coordinates_randomly((2, 3))),
    // ╭───────╮
    // │ ? ? ? │
    // │ ?   W │
    // │ ?   ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            None,
            None,
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(None),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((3, 2)), Direction::South, *RANDOM_BOOL, false),
)]
// endregion
// region curr. dir E, wanted slot W, curr. slot E, cursor N border, curr. slot reached
#[case::curr_dir_e_wanted_slot_w_curr_slot_e_cursor_n_border_curr_slot_reached(
    pad_coordinates_randomly((1, 3)),
    Direction::West,
    pad_coordinates_randomly((1, 2)),
    Direction::East,
    true,
    Some(pad_coordinates_randomly((1, 1))),
    // ╭───────╮
    // │ W   C │
    // │ ? ₂ ? │
    // │ ? ? ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            None,
            None,
            None,
        ],
        [
            None,
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(2, 5))),
            None,
        ],
        [
            None,
            None,
            create_grid_slot_or_none(),
            None,
        ],
    ]),
    (pad_coordinates_randomly((1, 3)), Direction::East, true, false),
)]
// endregion
// region curr. dir E, wanted slot W, cursor center, no slot E, go E
#[case::curr_dir_e_wanted_slot_w_cursor_center_no_slot_e_go_e(
    pad_coordinates_randomly((1, rand_usize(1, 4))),
    Direction::South,
    pad_coordinates_randomly((2, 2)),
    Direction::East,
    *RANDOM_BOOL,
    Some(pad_coordinates_randomly((2, 1))),
    // ╭───────╮
    // │ ? ? ? │
    // │ W     │
    // │ ? ₂ ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            None,
            None,
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(2, 5))),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((2, 3)), Direction::East, *RANDOM_BOOL, false),
)]
// endregion
// region curr. dir E, wanted slot W, cursor center, no slot E, go E, exposed S
#[case::curr_dir_e_wanted_slot_w_cursor_center_no_slot_e_go_e_exposed_s(
    pad_coordinates_randomly((rand_usize(1, 4), 1)),
    Direction::South,
    pad_coordinates_randomly((2, 2)),
    Direction::East,
    *RANDOM_BOOL,
    Some(pad_coordinates_randomly((2, 1))),
    // ╭───────╮
    // │ ? ? ? │
    // │ W     │
    // │ ? ₇ ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            None,
            None,
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(7, 10))),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((2, 3)), Direction::East, true, false),
)]
// endregion
// region curr. dir E, wanted slot W, cursor center, no slot N, go N
#[case::curr_dir_e_wanted_slot_w_cursor_center_no_slot_n_go_n(
    pad_coordinates_randomly((rand_usize(1, 4), 1)),
    Direction::South,
    pad_coordinates_randomly((2, 2)),
    Direction::East,
    *RANDOM_BOOL,
    Some(pad_coordinates_randomly((2, 1))),
    // ╭───────╮
    // │ ?   ? │
    // │ W   ³ │
    // │ ? ₂ ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            None,
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(0, 4))),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(2, 5))),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((1, 2)), Direction::North, *RANDOM_BOOL, false),
)]
// endregion
// region curr. dir E, wanted slot W, cursor center, no slot N, go N, exposed E
#[case::curr_dir_e_wanted_slot_w_cursor_center_no_slot_n_go_n_exposed_e(
    pad_coordinates_randomly((rand_usize(1, 4), 1)),
    Direction::South,
    pad_coordinates_randomly((2, 2)),
    Direction::East,
    *RANDOM_BOOL,
    Some(pad_coordinates_randomly((2, 1))),
    // ╭───────╮
    // │ ?   ? │
    // │ W   ⁸ │
    // │ ? ₂ ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            None,
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(4, 9))),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(2, 5))),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((1, 2)), Direction::North, true, false),
)]
// endregion
// region curr. dir E, wanted slot W, cursor center, no tile N, go N
#[case::curr_dir_e_wanted_slot_w_cursor_center_no_tile_n_go_n(
    pad_coordinates_randomly((rand_usize(1, 4), 1)),
    Direction::South,
    pad_coordinates_randomly((2, 2)),
    Direction::East,
    *RANDOM_BOOL,
    Some(pad_coordinates_randomly((2, 1))),
    // ╭───────╮
    // │ ?   ? │
    // │ ₃   ³ │
    // │ ? ₂ ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(None),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(3, 5))),
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(0, 4))),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(2, 5))),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((1, 2)), Direction::North, *RANDOM_BOOL, false),
)]
// endregion
// region curr. dir E, wanted slot W, cursor center, no tile N, go N, exposed E and S
#[case::curr_dir_e_wanted_slot_w_cursor_center_no_tile_n_go_n_exposed_e_and_s(
    pad_coordinates_randomly((rand_usize(1, 4), 1)),
    Direction::South,
    pad_coordinates_randomly((2, 2)),
    Direction::East,
    *RANDOM_BOOL,
    Some(pad_coordinates_randomly((2, 1))),
    // ╭───────╮
    // │ ?   ? │
    // │ ₃   ⁸ │
    // │ ? ₇ ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(None),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(3, 5))),
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(4, 9))),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(7, 10))),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((1, 2)), Direction::North, true, false),
)]
// endregion
// region curr. dir E, wanted slot SW, cursor center, nowhere to go, panic
#[should_panic(expected = "neither vacant nor wanted nor current slot found")]
#[case::curr_dir_e_wanted_slot_sw_cursor_center_nowhere_to_go_panic(
    pad_coordinates_randomly((1 + rand_usize(0, 2) * 2, 1 + rand_usize(0, 2) * 2)),
    random_direction(),
    pad_coordinates_randomly((2, 2)),
    Direction::East,
    rand_bool(),
    Some(pad_coordinates_randomly((3, 1))),
    // ╭───────╮
    // │ ? ² ? │
    // │ ₃   ³ │
    // │ W ₂ ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(0, 3))),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(3, 5))),
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(0, 4))),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(2, 5))),
            create_grid_slot_or_none(),
        ],
    ]),
    (
        (rand_usize(0, 9), rand_usize(0, 9)),
        random_direction(),
        rand_bool(),
        rand_bool(),
    ),
)]
// endregion
// region curr. dir E, wanted slot SW, cursor center, nowhere to go, exposed W, panic
#[should_panic(expected = "neither vacant nor wanted nor current slot found")]
#[case::curr_dir_e_wanted_slot_sw_cursor_center_nowhere_to_go_exposed_w_panic(
    pad_coordinates_randomly((1 + rand_usize(0, 2) * 2, 1 + rand_usize(0, 2) * 2)),
    random_direction(),
    pad_coordinates_randomly((2, 2)),
    Direction::East,
    rand_bool(),
    Some(pad_coordinates_randomly((3, 1))),
    // ╭───────╮
    // │ ? ² ? │
    // │ ₈   ³ │
    // │ W ₂ ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(0, 3))),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(8, 10))),
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(0, 4))),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(2, 5))),
            create_grid_slot_or_none(),
        ],
    ]),
    (
        (rand_usize(0, 9), rand_usize(0, 9)),
        random_direction(),
        rand_bool(),
        rand_bool(),
    ),
)]
// endregion
// region curr. dir E, maybe wanted slot SW, curr. slot blocked S, cursor center, no tile E, go E
#[case::curr_dir_e_maybe_wanted_slot_sw_curr_slot_blocked_s_cursor_center_no_tile_e_go_e(
    pad_coordinates_randomly((3, 2)),
    if rand_bool() { Direction::West } else { Direction::East },
    pad_coordinates_randomly((2, 2)),
    Direction::East,
    *RANDOM_BOOL,
    if rand_bool() { Some(pad_coordinates_randomly((3, 3))) } else { None },
    // ╭───────╮
    // │ ? ? ? │
    // │ ?     │
    // │ ?   ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            None,
            None,
        ],
        [
            None,
            create_grid_slot_or_none(),
            None,
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((2, 3)), Direction::East, *RANDOM_BOOL, false),
)]
// endregion
// region curr. dir S, no wanted slot, curr. slot E, cursor center, curr. slot reached
#[case::curr_dir_s_no_wanted_slot_curr_slot_e_cursor_center_curr_slot_reached(
    pad_coordinates_randomly((2, 3)),
    Direction::West,
    pad_coordinates_randomly((2, 2)),
    Direction::South,
    *RANDOM_BOOL,
    None,
    // ╭───────╮
    // │ ? ? ? │
    // │ ₃   C │
    // │ ? ₂ ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(3, 5))),
            None,
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(2, 5))),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((2, 3)), Direction::East, *RANDOM_BOOL, false),
)]
// endregion
// region curr. dir S, no wanted slot, curr. slot E, cursor center, curr. slot reached, exposed W
#[case::curr_dir_s_no_wanted_slot_curr_slot_e_cursor_center_curr_slot_reached_exposed_w(
    pad_coordinates_randomly((2, 3)),
    Direction::West,
    pad_coordinates_randomly((2, 2)),
    Direction::South,
    *RANDOM_BOOL,
    None,
    // ╭───────╮
    // │ ? ? ? │
    // │ ₈   C │
    // │ ? ₂ ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(8, 10))),
            None,
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(2, 5))),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((2, 3)), Direction::East, true, false),
)]
// endregion
// region curr. dir S, no wanted slot, curr. slot E, cursor center, curr. slot reached, exposed S
#[case::curr_dir_s_no_wanted_slot_curr_slot_e_cursor_center_curr_slot_reached_exposed_s(
    pad_coordinates_randomly((2, 3)),
    Direction::West,
    pad_coordinates_randomly((2, 2)),
    Direction::South,
    *RANDOM_BOOL,
    None,
    // ╭───────╮
    // │ ? ? ? │
    // │ ₃   C │
    // │ ? ₇ ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(3, 5))),
            None,
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(7, 10))),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((2, 3)), Direction::East, true, false),
)]
// endregion
// region curr. dir S, no wanted slot, curr. slot W, cursor S border, curr. slot reached
#[case::curr_dir_s_no_wanted_slot_curr_slot_w_cursor_s_border_curr_slot_reached(
    pad_coordinates_randomly((3, 1)),
    Direction::East,
    pad_coordinates_randomly((3, 2)),
    Direction::South,
    *RANDOM_BOOL,
    None,
    // ╭───────╮
    // │ ? ? ? │
    // │ ? ? ? │
    // │ C   ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            None,
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((3, 1)), Direction::West, *RANDOM_BOOL, false),
)]
// endregion
// region curr. dir S, wanted slot W past border, curr. slot S, cursor W border, curr. slot reached
#[case::curr_dir_s_wanted_slot_w_past_border_curr_slot_s_cursor_w_border_curr_slot_reached(
    (3 + *RANDOM_USIZE, 1),
    Direction::North,
    (2 + *RANDOM_USIZE, 1),
    Direction::South,
    *RANDOM_BOOL,
    Some((2 + *RANDOM_USIZE, 0)),
    //  ╭───────╮
    //  │ ? ? ? │
    // W│   ? ? │
    //  │ C ? ? │
    //  ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
        [
            None,
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
    ]),
    (
        (3 + *RANDOM_USIZE, 1),
        Direction::South,
        *RANDOM_BOOL,
        false,
    ),
)]
// endregion
// region curr. dir S, wanted slot S, cursor center, no slot W, go W
#[case::curr_dir_s_wanted_slot_s_cursor_center_no_slot_w_go_w(
    pad_coordinates_randomly((1, rand_usize(1, 4))),
    Direction::South,
    pad_coordinates_randomly((2, 2)),
    Direction::South,
    *RANDOM_BOOL,
    Some(pad_coordinates_randomly((3, 2))),
    // ╭───────╮
    // │ ? ? ? │
    // │     ? │
    // │ ? W ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
        [
            None,
            None,
            None,
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            None,
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((2, 1)), Direction::West, *RANDOM_BOOL, false),
)]
// endregion
// region curr. dir S, wanted slot S, cursor center, no tile W, go W
#[case::curr_dir_s_wanted_slot_s_cursor_center_no_tile_w_go_w(
    pad_coordinates_randomly((1, rand_usize(1, 4))),
    Direction::South,
    pad_coordinates_randomly((2, 2)),
    Direction::South,
    *RANDOM_BOOL,
    Some(pad_coordinates_randomly((3, 2))),
    // ╭───────╮
    // │ ? ? ? │
    // │     ? │
    // │ ? W ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_with_tile_id(None),
            None,
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            None,
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((2, 1)), Direction::West, *RANDOM_BOOL, false),
)]
// endregion
// region curr. dir S, wanted slot N, curr. slot S, cursor E border, curr. slot reached
#[case::curr_dir_s_wanted_slot_n_curr_slot_s_cursor_e_border_curr_slot_reached(
    pad_coordinates_randomly((3, 3)),
    Direction::North,
    pad_coordinates_randomly((2, 3)),
    Direction::South,
    true,
    Some(pad_coordinates_randomly((1, 3))),
    // ╭───────╮
    // │ ? ? W │
    // │ ? ₃   │
    // │ ? ? C │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            None,
            None,
            None,
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(3, 5))),
            None,
        ],
        [
            None,
            None,
            None,
            None,
        ],
    ]),
    (pad_coordinates_randomly((3, 3)), Direction::South, true, false),
)]
// endregion
// region curr. dir S, wanted slot N, cursor center, no slot S, go S
#[case::curr_dir_s_wanted_slot_n_cursor_center_no_slot_s_go_s(
    pad_coordinates_randomly((1, rand_usize(1, 4))),
    Direction::South,
    pad_coordinates_randomly((2, 2)),
    Direction::South,
    *RANDOM_BOOL,
    Some(pad_coordinates_randomly((1, 2))),
    // ╭───────╮
    // │ ? W ? │
    // │ ₃   ? │
    // │ ?   ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(3, 5))),
            None,
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            None,
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((3, 2)), Direction::South, *RANDOM_BOOL, false),
)]
// endregion
// region curr. dir S, wanted slot N, cursor center, no slot S, go S, exposed W
#[case::curr_dir_s_wanted_slot_n_cursor_center_no_slot_s_go_s_exposed_w(
    pad_coordinates_randomly((1, rand_usize(1, 4))),
    Direction::South,
    pad_coordinates_randomly((2, 2)),
    Direction::South,
    *RANDOM_BOOL,
    Some(pad_coordinates_randomly((1, 2))),
    // ╭───────╮
    // │ ? W ? │
    // │ ₈   ? │
    // │ ?   ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(8, 10))),
            None,
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            None,
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((3, 2)), Direction::South, true, false),
)]
// endregion
// region curr. dir S, wanted slot N, cursor center, no slot E, go E
#[case::curr_dir_s_wanted_slot_n_cursor_center_no_slot_e_go_e(
    pad_coordinates_randomly((1, rand_usize(1, 4))),
    Direction::South,
    pad_coordinates_randomly((2, 2)),
    Direction::South,
    *RANDOM_BOOL,
    Some(pad_coordinates_randomly((1, 2))),
    // ╭───────╮
    // │ ? W ? │
    // │ ₃     │
    // │ ? ₂ ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(3, 5))),
            None,
            None,
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(2, 5))),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((2, 3)), Direction::East, *RANDOM_BOOL, false),
)]
// endregion
// region curr. dir S, wanted slot N, cursor center, no slot E, go E, exposed S
#[case::curr_dir_s_wanted_slot_n_cursor_center_no_slot_e_go_e_exposed_s(
    pad_coordinates_randomly((1, rand_usize(1, 4))),
    Direction::South,
    pad_coordinates_randomly((2, 2)),
    Direction::South,
    *RANDOM_BOOL,
    Some(pad_coordinates_randomly((1, 2))),
    // ╭───────╮
    // │ ? W ? │
    // │ ₃     │
    // │ ? ₇ ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(3, 5))),
            None,
            None,
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(7, 10))),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((2, 3)), Direction::East, true, false),
)]
// endregion
// region curr. dir S, wanted slot N, cursor center, no tile E, go E
#[case::curr_dir_s_wanted_slot_n_cursor_center_no_tile_e_go_e(
    pad_coordinates_randomly((1, rand_usize(1, 4))),
    random_direction(),
    pad_coordinates_randomly((2, 2)),
    Direction::South,
    *RANDOM_BOOL,
    Some(pad_coordinates_randomly((1, 2))),
    // ╭───────╮
    // │ ? ² ? │
    // │ ₃     │
    // │ ? ₂ ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(0, 3))),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(3, 5))),
            None,
            create_grid_slot_with_tile_id(None),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(2, 5))),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((2, 3)), Direction::East, *RANDOM_BOOL, false),
)]
// endregion
// region curr. dir S, wanted slot N, cursor center, no tile E, go E, exposed S and W
#[case::curr_dir_s_wanted_slot_n_cursor_center_no_tile_e_go_e_exposed_s_and_w(
    pad_coordinates_randomly((1, rand_usize(1, 4))),
    random_direction(),
    pad_coordinates_randomly((2, 2)),
    Direction::South,
    *RANDOM_BOOL,
    Some(pad_coordinates_randomly((1, 2))),
    // ╭───────╮
    // │ ? ² ? │
    // │ ₈     │
    // │ ? ₇ ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(0, 3))),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(8, 10))),
            None,
            create_grid_slot_with_tile_id(None),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(7, 10))),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((2, 3)), Direction::East, true, false),
)]
// endregion
// region curr. dir S, wanted slot NW, cursor center, nowhere to go, panic
#[should_panic(expected = "neither vacant nor wanted nor current slot found")]
#[case::curr_dir_s_wanted_slot_nw_cursor_center_nowhere_to_go_panic(
    pad_coordinates_randomly((1 + rand_usize(0, 2) * 2, 1 + rand_usize(0, 2) * 2)),
    random_direction(),
    pad_coordinates_randomly((2, 2)),
    Direction::South,
    rand_bool(),
    Some(pad_coordinates_randomly((1, 1))),
    // ╭───────╮
    // │ W ² ? │
    // │ ₃   ³ │
    // │ ? ₂ ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(0, 3))),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(3, 5))),
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(0, 4))),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(2, 5))),
            create_grid_slot_or_none(),
        ],
    ]),
    (
        (rand_usize(0, 9), rand_usize(0, 9)),
        random_direction(),
        rand_bool(),
        rand_bool(),
    ),
)]
// endregion
// region curr. dir S, wanted slot NW, cursor center, nowhere to go, exposed N, panic
#[should_panic(expected = "neither vacant nor wanted nor current slot found")]
#[case::curr_dir_s_wanted_slot_nw_cursor_center_nowhere_to_go_exposed_n_panic(
    pad_coordinates_randomly((1 + rand_usize(0, 2) * 2, 1 + rand_usize(0, 2) * 2)),
    random_direction(),
    pad_coordinates_randomly((2, 2)),
    Direction::South,
    rand_bool(),
    Some(pad_coordinates_randomly((1, 1))),
    // ╭───────╮
    // │ W ⁷ ? │
    // │ ₃   ³ │
    // │ ? ₂ ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(5, 8))),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(3, 5))),
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(0, 4))),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(2, 5))),
            create_grid_slot_or_none(),
        ],
    ]),
    (
        (rand_usize(0, 9), rand_usize(0, 9)),
        random_direction(),
        rand_bool(),
        rand_bool(),
    ),
)]
// endregion
// region curr. dir S, maybe wanted slot NW, curr. slot blocked S, cursor center, no tile E, go E
#[case::curr_dir_s_maybe_wanted_slot_nw_curr_slot_blocked_s_cursor_center_no_tile_e_go_e(
    pad_coordinates_randomly((3, 2)),
    if rand_bool() { Direction::West } else { Direction::East },
    pad_coordinates_randomly((2, 2)),
    Direction::South,
    *RANDOM_BOOL,
    if rand_bool() { Some(pad_coordinates_randomly((1, 1))) } else { None },
    // ╭───────╮
    // │ W ⁷ ? │
    // │ ₃     │
    // │ ?   ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(5, 8))),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(3, 5))),
            None,
            None,
        ],
        [
            None,
            create_grid_slot_or_none(),
            None,
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((2, 3)), Direction::East, *RANDOM_BOOL, false),
)]
// endregion
// region curr. dir W, no wanted slot, curr. slot S, cursor center, curr. slot reached
#[case::curr_dir_w_no_wanted_slot_curr_slot_s_cursor_center_curr_slot_reached(
    pad_coordinates_randomly((3, 2)),
    Direction::North,
    pad_coordinates_randomly((2, 2)),
    Direction::West,
    *RANDOM_BOOL,
    None,
    // ╭───────╮
    // │ ? ² ? │
    // │ ₃   ? │
    // │ ? C ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(0, 3))),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(3, 5))),
            None,
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((3, 2)), Direction::South, *RANDOM_BOOL, false),
)]
// endregion
// region curr. dir W, no wanted slot, curr. slot S, cursor center, curr. slot reached, exposed N
#[case::curr_dir_w_no_wanted_slot_curr_slot_s_cursor_center_curr_slot_reached_exposed_n(
    pad_coordinates_randomly((3, 2)),
    Direction::North,
    pad_coordinates_randomly((2, 2)),
    Direction::West,
    *RANDOM_BOOL,
    None,
    // ╭───────╮
    // │ ? ⁷ ? │
    // │ ₃   ? │
    // │ ? C ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(5, 8))),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(3, 5))),
            None,
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((3, 2)), Direction::South, true, false),
)]
// endregion
// region curr. dir W, no wanted slot, curr. slot S, cursor center, curr. slot reached, exposed W
#[case::curr_dir_w_no_wanted_slot_curr_slot_s_cursor_center_curr_slot_reached_exposed_w(
    pad_coordinates_randomly((3, 2)),
    Direction::North,
    pad_coordinates_randomly((2, 2)),
    Direction::West,
    *RANDOM_BOOL,
    None,
    // ╭───────╮
    // │ ? ² ? │
    // │ ₈   ? │
    // │ ? C ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(0, 3))),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(8, 10))),
            None,
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((3, 2)), Direction::South, true, false),
)]
// endregion
// region curr. dir W, no wanted slot, curr. slot N, cursor W border, curr. slot reached
#[case::curr_dir_w_no_wanted_slot_curr_slot_n_cursor_w_border_curr_slot_reached(
    pad_coordinates_randomly((1, 1)),
    Direction::South,
    pad_coordinates_randomly((2, 1)),
    Direction::West,
    *RANDOM_BOOL,
    None,
    // ╭───────╮
    // │ C ? ? │
    // │   ? ? │
    // │ ? ? ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
        [
            None,
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((1, 1)), Direction::North, *RANDOM_BOOL, false),
)]
// endregion
// region curr. dir W, wanted slot N past border, curr. slot W, cursor N border, curr. slot reached
#[case::curr_dir_w_wanted_slot_n_past_border_curr_slot_w_cursor_n_border_curr_slot_reached(
    (1, 1),
    Direction::East,
    (1, 2),
    Direction::West,
    *RANDOM_BOOL,
    Some((0, 2)),
    //     W
    // ╭───────╮
    // │ C   ? │
    // │ ? ? ? │
    // │ ? ? ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            None,
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
    ]),
    (
        (1, 1),
        Direction::West,
        *RANDOM_BOOL,
        false,
    ),
)]
// endregion
// region curr. dir W, wanted slot W, cursor center, no slot N, go N
#[case::curr_dir_w_wanted_slot_w_cursor_center_no_slot_n_go_n(
    pad_coordinates_randomly((rand_usize(1, 4), 3)),
    random_direction(),
    pad_coordinates_randomly((2, 2)),
    Direction::West,
    *RANDOM_BOOL,
    Some(pad_coordinates_randomly((2, 1))),
    // ╭───────╮
    // │ ?   ? │
    // │ W   ? │
    // │ ? ? ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            None,
            create_grid_slot_or_none(),
        ],
        [
            None,
            None,
            None,
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((1, 2)), Direction::North, *RANDOM_BOOL, false),
)]
// endregion
// region curr. dir W, wanted slot W, cursor center, no tile N, go N
#[case::curr_dir_w_wanted_slot_w_cursor_center_no_tile_n_go_n(
    pad_coordinates_randomly((rand_usize(1, 4), 3)),
    random_direction(),
    pad_coordinates_randomly((2, 2)),
    Direction::West,
    *RANDOM_BOOL,
    Some(pad_coordinates_randomly((2, 1))),
    // ╭───────╮
    // │ ?   ? │
    // │ W   ? │
    // │ ? ? ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(None),
            create_grid_slot_or_none(),
        ],
        [
            None,
            None,
            None,
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((1, 2)), Direction::North, *RANDOM_BOOL, false),
)]
// endregion
// region curr. dir W, wanted slot E, curr. slot W, cursor S border, curr. slot reached
#[case::curr_dir_w_wanted_slot_e_curr_slot_w_cursor_s_border_curr_slot_reached(
    pad_coordinates_randomly((3, 1)),
    Direction::East,
    pad_coordinates_randomly((3, 2)),
    Direction::West,
    true,
    Some(pad_coordinates_randomly((3, 3))),
    // ╭───────╮
    // │ ? ? ? │
    // │ ? ² ? │
    // │ C   W │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            None,
            create_grid_slot_or_none(),
            None,
        ],
        [
            None,
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(0, 3))),
            None,
        ],
        [
            None,
            None,
            None,
            None,
        ],
    ]),
    (pad_coordinates_randomly((3, 1)), Direction::West, true, false),
)]
// endregion
// region curr. dir W, wanted slot E, cursor center, no slot W, go W
#[case::curr_dir_w_wanted_slot_e_cursor_center_no_slot_w_go_w(
    pad_coordinates_randomly((rand_usize(1, 4), 3)),
    random_direction(),
    pad_coordinates_randomly((2, 2)),
    Direction::West,
    *RANDOM_BOOL,
    Some(pad_coordinates_randomly((2, 3))),
    // ╭───────╮
    // │ ? ² ? │
    // │     W │
    // │ ? ? ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(0, 3))),
            create_grid_slot_or_none(),
        ],
        [
            None,
            None,
            None,
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((2, 1)), Direction::West, *RANDOM_BOOL, false),
)]
// endregion
// region curr. dir W, wanted slot E, cursor center, no slot W, go W, exposed N
#[case::curr_dir_w_wanted_slot_e_cursor_center_no_slot_w_go_w_exposed_n(
    pad_coordinates_randomly((rand_usize(1, 4), 3)),
    random_direction(),
    pad_coordinates_randomly((2, 2)),
    Direction::West,
    *RANDOM_BOOL,
    Some(pad_coordinates_randomly((2, 3))),
    // ╭───────╮
    // │ ? ⁷ ? │
    // │     W │
    // │ ? ? ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(5, 8))),
            create_grid_slot_or_none(),
        ],
        [
            None,
            None,
            None,
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((2, 1)), Direction::West, true, false),
)]
// endregion
// region curr. dir W, wanted slot E, cursor center, no slot S, go S
#[case::curr_dir_w_wanted_slot_e_cursor_center_no_slot_s_go_s(
    pad_coordinates_randomly((rand_usize(1, 4), 3)),
    random_direction(),
    pad_coordinates_randomly((2, 2)),
    Direction::West,
    *RANDOM_BOOL,
    Some(pad_coordinates_randomly((2, 3))),
    // ╭───────╮
    // │ ? ² ? │
    // │ ₃   W │
    // │ ?   ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(0, 3))),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(3, 5))),
            None,
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            None,
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((3, 2)), Direction::South, *RANDOM_BOOL, false),
)]
// endregion
// region curr. dir W, wanted slot E, cursor center, no slot S, go S, exposed W
#[case::curr_dir_w_wanted_slot_e_cursor_center_no_slot_s_go_s_exposed_w(
    pad_coordinates_randomly((rand_usize(1, 4), 3)),
    random_direction(),
    pad_coordinates_randomly((2, 2)),
    Direction::West,
    *RANDOM_BOOL,
    Some(pad_coordinates_randomly((2, 3))),
    // ╭───────╮
    // │ ? ² ? │
    // │ ₈   W │
    // │ ?   ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(0, 3))),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(8, 10))),
            None,
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            None,
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((3, 2)), Direction::South, true, false),
)]
// endregion
// region curr. dir W, wanted slot E, cursor center, no tile S, go S
#[case::curr_dir_w_wanted_slot_e_cursor_center_no_tile_s_go_s(
    pad_coordinates_randomly((rand_usize(1, 4), 3)),
    random_direction(),
    pad_coordinates_randomly((2, 2)),
    Direction::West,
    *RANDOM_BOOL,
    Some(pad_coordinates_randomly((2, 3))),
    // ╭───────╮
    // │ ? ² ? │
    // │ ₃   ³ │
    // │ ?   ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(0, 3))),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(3, 5))),
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(0, 4))),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(None),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((3, 2)), Direction::South, *RANDOM_BOOL, false),
)]
// endregion
// region curr. dir W, wanted slot E, cursor center, no tile S, go S, exposed W and N
#[case::curr_dir_w_wanted_slot_e_cursor_center_no_tile_s_go_s_exposed_w_and_n(
    pad_coordinates_randomly((rand_usize(1, 4), 3)),
    random_direction(),
    pad_coordinates_randomly((2, 2)),
    Direction::West,
    *RANDOM_BOOL,
    Some(pad_coordinates_randomly((2, 3))),
    // ╭───────╮
    // │ ? ⁷ ? │
    // │ ₈   ³ │
    // │ ?   ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(5, 8))),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(8, 10))),
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(0, 4))),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(None),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((3, 2)), Direction::South, true, false),
)]
// endregion
// region curr. dir W, wanted slot NE, cursor center, nowhere to go, panic
#[should_panic(expected = "neither vacant nor wanted nor current slot found")]
#[case::curr_dir_w_wanted_slot_ne_cursor_center_nowhere_to_go_panic(
    pad_coordinates_randomly((1 + rand_usize(0, 2) * 2, 1 + rand_usize(0, 2) * 2)),
    random_direction(),
    pad_coordinates_randomly((2, 2)),
    Direction::West,
    rand_bool(),
    Some(pad_coordinates_randomly((1, 3))),
    // ╭───────╮
    // │ ? ² W │
    // │ ₃   ³ │
    // │ ? ₂ ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(0, 3))),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(3, 5))),
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(0, 4))),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(2, 5))),
            create_grid_slot_or_none(),
        ],
    ]),
    (
        (rand_usize(0, 9), rand_usize(0, 9)),
        random_direction(),
        rand_bool(),
        rand_bool(),
    ),
)]
// endregion
// region curr. dir W, wanted slot NE, cursor center, nowhere to go, exposed E, panic
#[should_panic(expected = "neither vacant nor wanted nor current slot found")]
#[case::curr_dir_w_wanted_slot_ne_cursor_center_nowhere_to_go_exposed_e_panic(
    pad_coordinates_randomly((1 + rand_usize(0, 2) * 2, 1 + rand_usize(0, 2) * 2)),
    random_direction(),
    pad_coordinates_randomly((2, 2)),
    Direction::West,
    rand_bool(),
    Some(pad_coordinates_randomly((1, 3))),
    // ╭───────╮
    // │ ? ² W │
    // │ ₃   ⁸ │
    // │ ? ₂ ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(0, 3))),
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(3, 5))),
            None,
            create_grid_slot_with_tile_id(Some(rand_usize(4, 9))),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_with_tile_id(Some(rand_usize(2, 5))),
            create_grid_slot_or_none(),
        ],
    ]),
    (
        (rand_usize(0, 9), rand_usize(0, 9)),
        random_direction(),
        rand_bool(),
        rand_bool(),
    ),
)]
// endregion
// region curr. dir W, maybe wanted slot NE, curr. slot blocked N, cursor center, no tile W, go W
#[case::curr_dir_w_maybe_wanted_slot_ne_curr_slot_blocked_n_cursor_center_no_tile_w_go_w(
    pad_coordinates_randomly((1, 2)),
    if rand_bool() { Direction::North } else { Direction::East },
    pad_coordinates_randomly((2, 2)),
    Direction::West,
    *RANDOM_BOOL,
    if rand_bool() { Some(pad_coordinates_randomly((3, 3))) } else { None },
    // ╭───────╮
    // │ ?   ? │
    // │     ? │
    // │ ? ? ? │
    // ╰───────╯
    pad_grid_randomly(array![
        [None, None, None, None],
        [
            None,
            create_grid_slot_or_none(),
            None,
            create_grid_slot_or_none(),
        ],
        [
            None,
            None,
            None,
            create_grid_slot_or_none(),
        ],
        [
            None,
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
            create_grid_slot_or_none(),
        ],
    ]),
    (pad_coordinates_randomly((2, 1)), Direction::West, *RANDOM_BOOL, false),
)]
// endregion
fn test_find_next_slot_in_neighbor_association(
    #[case] current_slot: (usize, usize),
    #[case] first_neighbor_direction: Direction,
    #[case] cursor: (usize, usize),
    #[case] current_direction: Direction,
    #[case] exposed_edge_found: bool,
    #[case] wanted_slot: Option<(usize, usize)>,
    #[case] grid: Array2<Option<GridSlot>>,
    #[case] expected_result: ((usize, usize), Direction, bool, bool),
) {
    let tile_list = neighbor_association_tile_list();
    let slot_grid = SlotGrid {
        num_rows: grid.nrows(),
        num_cols: grid.ncols(),
        grid,
        border_tile_id: if rand_bool() {
            None
        } else {
            Some(rand_usize(0, 9))
        },
        tile_connections: TileConnectionArray::new(&tile_list.tiles),
        tile_list,
        missing_tile_policy: random_missing_tile_policy(),
        tile_selection_policy: random_tile_selection_policy(),
        vacancy_policy: RANDOM_VACANCY_POLICY.clone(),
        current_slot,
        current_predecessor: random_predecessor(),
        last_leaves: random_last_leaves(),
        exposed_edge_count: rand_usize(0, 19),
    };

    let result = slot_grid.find_next_slot_in_neighbor_association(
        first_neighbor_direction,
        cursor,
        current_direction,
        exposed_edge_found,
        wanted_slot,
    );

    assert_eq!(result, expected_result);
    // Access slot_grid to ensure it was not moved.
    drop(slot_grid);
}
